<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>后台管理模板</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
		<link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
		<style type="text/css">
			.d-to {
				float: left;
				margin: 10px 80px;
			}
			
			.d-title {
				font-size: 20px;
				margin-bottom: 10px
			}
			
			.d-item {
				font-size: 25px;
				color: #1AA094;
			}
			
			.layui-body {}
			
			.datalist {
				text-align: center;
				margin-left: 40px
			}
			
			.money {
				height: 300px;
				width: 550px;
				float: left;
				margin-left: 35px;
			}
			
			.money img {
				border-radius: 0;
				height: 166px;
				width: 166px;
				margin-top: 70px;
				margin-left: 50px;
				float: left;
			}
			
			#moneyIn {
				float: left;
				margin-top: 100px;
				margin-left: 20px;
			}
			
			.money_title {
				font-size: 24px;
				color: rgb(152, 143, 131);
				text-align: center;
			}
			
			.money_number {
				font-size: 50px;
				margin-top: 20px;
				color: rgb(175, 122, 57);
				font-weight: 800;
			}
			
			#moneyOut {
				float: left;
				margin-top: 100px;
				margin-left: 20px;
			}
			
			.mvp {
				position: relative;
				top: 380px;
				left: 80px;
				font-size: 20px;
				line-height: 50px;
			}
			
			.mvp_1 {
				float: left;
				margin-right: 100px;
				margin-bottom: 200px;
			}
			
			.mvp_2 {
				float: left;
			}
			
			.mvp table {
				border-width: 1px
			}
			
			.award {
				width: 60px;
				margin: 5px;
			}
			
			table {
				border: 1px solid #cccccc;
			}
			
			th,
			td {
				border: 1px solid #cccccc;
				width: 190px;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
			<!--头部导航-->
			<div class="layui-header header header-demo"></div>
			<!--左侧导航-->
			<div class="layui-side layui-bg-black" id="admin-side">
			</div>
			<!--右侧具体内容-->
			<div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
				<div class="datalist">
					<div class="d-to">
						<div class="d-title">今日完成订单</div>
						<div class="d-item todayOrder"></div>
					</div>
					<div class="d-to">
						<div class="d-title">历史完成订单</div>
						<div class="d-item totalOrder"></div>
					</div>
					<div class="d-to">
						<div class="d-title">用户人数</div>
						<div class=" d-item totalUser"></div>
					</div>
					<div class="d-to">
						<div class="d-title">快递人数</div>
						<div class="d-item totalCourier"></div>
					</div>
				</div>
				<hr>
				<div class="money">
					<img src="../../images/yen_gold.png">
					<div id="moneyIn">
						<div class="money_title">今日流入金额</div>
						<div class="money_number"></div>
					</div>
				</div>
				<div class="money">
					<img src="../../images/yen_gold.png">
					<div id="moneyOut">
						<div class="money_title">今日流出金额</div>
						<div class="money_number"></div>
					</div>
				</div>
				<div id="main" style="width: 1200px;height:400px;"></div>
				<div id="main2" style="width: 1200px;height:400px;top: 300px;"></div>
				<div class="mvp">
					<div class="mvp_1">
						<table id="table_topUser">
							<tr>
								<th>排名</th>
								<th>活跃用户</th>
								<th>相关订单数</th>
							</tr>
							<tr>
								<td><img class="award" src="../../images/gold.png"></td>
								<td><img src="../../images/am.jpg"> 小白兔</td>
								<td>66</td>
							</tr>
							<tr>
								<td><img class="award" src="../../images/gold.png"></td>
								<td><img src="../../images/0.jpg"> 大灰狼</td>
								<td>66</td>
							</tr>
							<tr>
								<td><img class="award" src="../../images/cu.png"></td>
								<td><img src="../../images/xiaosong.jpg"> 朵拉la</td>
								<td>66</td>
							</tr>
						</table>
					</div>
					<div class="mvp_2">
						<table id="table_topCourier">
							<tr>
								<th>排名</th>
								<th>活跃快递员</th>
								<th>总接单数</th>
							</tr>
							<tr>
								<td><img class="award" src="../../images/gold.png"></td>
								<td><img src="../../images/jn.jpg"> czl</td>
								<td>66</td>
							</tr>
							<tr>
								<td><img class="award" src="../../images/gold.png"></td>
								<td><img src="../../images/find_1.png"> lzy</td>
								<td>66</td>
							</tr>
							<tr>
								<td><img class="award" src="../../images/cu.png"></td>
								<td><img src="../../images/mm.jpg"> slc</td>
								<td>66</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
		<!--底部导航-->
		<!-- <div class="layui-footer footer footer-demo" id="admin-footer"></div> -->
		<!--JS模块-->
		<script type="text/javascript" src="../../layui/layui.js"></script>
		<script src="../../js/jquery-1.12.3.min.js"></script>
		<script type="text/javascript" src="../../js/jquery.cookie.js"></script>
		<script type="text/javascript" src="http://echarts.baidu.com/dist/echarts.js"></script>
		<script type="text/javascript" src="../../js/count2.js"></script>
		<script src="../../js/index.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				addTopUser();
				addTopCourier();

				getDifferentOrder();

				$("#datareport").addClass('layui-this');
				var data1 = {
					"code": 200,
					"count": 77763
				}
				$.ajax({
					url: '/randomdelivery/AdminController/todayOrderCount',
					type: 'GET',
					dataType: "json",
					success: function(data) {
						//alert(JSON.stringify(data))
						if(data.code == 200)
							$(".todayOrder").text(data.count)

						else {
							alert("服务器出错")
						}
					}
				});
				//$(".todayOrder").text(data1.count);

				var data2 = {
					"code": 200,
					"count": 83083
				}
				$.ajax({
					url: '/randomdelivery/AdminController/totalOrder',
					type: 'GET',
					dataType: "json",
					success: function(data) {
						if(data.code == 200)
							$(".totalOrder").text(data.count);

						else {
							alert("服务器出错")
						}
					}
				});
				//$(".totalOrder").text(data2.count);

				var data3 = {
					"code": 200,
					"count": 55555
				}
				$.ajax({
					url: '/randomdelivery/AdminController/totalUser',
					type: 'GET',
					dataType: "json",
					data: {},
					success: function(data) {
						if(data.code == 200)
							$(".totalUser").text(data.count)

						else {
							alert("服务器出错")
						}
					}
				});
				//$(".totalUser").text(data3.count);

				var data4 = {
					"code": 200,
					"count": 6666
				}
				$.ajax({
					url: '/randomdelivery/AdminController/totalCourier',
					type: 'GET',
					dataType: "json",
					data: {},
					success: function(data) {
						if(data.code == 200)
							$(".totalCourier").text(data.count)

						else {
							alert("服务器出错")
						}
					}
				});
				//$(".totalCourier").text(data4.count);

				/*var data11 = { //今日流入金额
					"code": 200,
					"count": 15424
				}
				$("#moneyIn .money_number").numberRock({
					speed: 14, //数字越大数字滚动速度越慢
					count: data11.count //最终停留数字
				})

				var data12 = { //今日流出金额
					"code": 200,
					"count": 5424
				}
				$("#moneyOut .money_number").numberRock({
					speed: 14, //数字越大数字滚动速度越慢
					count: data12.count //最终停留数字
				})*/

				//关于资金流入流出的ajax
				$.ajax({
					url: '/randomdelivery/AdminController/inflowMoney',
					type: 'GET',
					dataType: "json",
					success: function(data) {
						if(data.code == 200) {							
							//alert(JSON.stringify(data))
							var money = parseInt(data.money)
							$("#moneyIn .money_number").numberRock({
								speed: 10, //数字越大数字滚动速度越慢
								count: 12000 //最终停留数字
								//count: money //最终停留数字
							})
							/*var now = new Date();
							var exitTime = now.getTime() + 200; 
							while(true)
							{
								var time2 = new Date();
								if((exitTime-time2.getTime())<=0)
								break;
							}*/
						} else {
							alert("服务器出错")
						}
					}
				});
				
				//关于资金流入流出的ajax
				$.ajax({
					url: '/randomdelivery/AdminController/outflowMoney',
					type: 'GET',
					dataType: "json",
					success: function(data) {
						if(data.code == 200) {
							//alert(JSON.stringify(data))
							var money = parseInt(data.money)
							$("#moneyOut .money_number").numberRock({
								speed: 10, //数字越大数字滚动速度越慢
								count: 8900 //最终停留数字
								//count: money //最终停留数字
							})
						} else {
							alert("服务器出错")
						}
					}
				});
				
				
				

				var data_state = {
					"code": 200,
					"orders": [{
						"state": "未接单",
						"count": 111
					}, {
						"state": "已接单",
						"count": 222
					}, {
						"state": "正在采购",
						"count": 333
					}, {
						"state": "采购完成",
						"count": 444
					}, {
						"state": "正在寄件",
						"count": 555
					}, {
						"state": "派送中",
						"count": 666
					}, {
						"state": "已关闭",
						"count": 777
					}, {
						"state": "待确认收货",
						"count": 888
					}, {
						"state": "待评价",
						"count": 999
					}]
				}
				/*$.ajax({
						url: '/AdminController/orderBystate',
						type: 'GET',
						dataType: "json",
						data: {},
						success: function (data) {
            			}
            		});*/
				//state(data_state);

				/*var data_usernum = {
					"code": 95789,
					"numberList": [
						16,
						50,
						84,
						123,
						234,
						456,
						678
					]
				}*/

				$.ajax({
					url: '/randomdelivery/AdminController/usersNumberByDay/7',
					type: 'GET',
					dataType: "json",
					success: function(data) {
						if(data.code == 200) {
							var data_usernum = data.numberList;
							data_usernum.reverse();
							//alert(data_usernum)
							userup(data_usernum)
						} else {
							alert("服务器出错")
						}
					}
				});

				function userup(data) {
					var date = []
					var usernum = []
					$.each(data, function(index, val) {
						//alert(this)
						date.push((7 - index) + "天前");
						usernum.push(val);
					});
					var myChart = echarts.init(document.getElementById('main2'));
					// 指定图表的配置项和数据
					var option = {
						title: {
							text: '日期-用户数'
						},
						tooltip: {},
						legend: {
							data: ['用户数']
						},
						xAxis: {
							data: date
						},
						yAxis: {},
						series: [{
							name: '用户数',
							type: 'line',
							data: usernum
						}]
					};
					// 使用刚指定的配置项和数据显示图表。
					myChart.setOption(option);
				}

				adminCookie()
				// C1=window.location.href.split("?")[1];
				// adminName=C1.split("=")[1].split("&&")[0]; 
				// headimg=C1.split("=")[2];
				// alert(C1);
				// alert(adminName);
				// alert(headimg)
			});

			function addTopUser() {

				$.ajax({
					url: "/randomdelivery/AdminController/topUser/3",
					type: "GET",
					success: function(data) {
						if(data.code == 200) {
							$("#table_topUser").text("")
							$("#table_topUser").append("<tr>\
					<th>排名</th>\
					<th>活跃用户</th>\
					<th>相关订单数</th>\
				</tr>");
							var index = 1;
							$.each(data.users, function() {
								//alert(JSON.stringify(this))
								//$("#table_topUser").append('<tr><td><img class="award" ') ;
								switch(index) {
									case 1:
										$("#table_topUser").append('<tr><td><img class="award" src="../../images/gold.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.userOrderSum + '</td>\
								</tr>')
										break;
									case 2:
										$("#table_topUser").append('<tr><td><img class="award" src="../../images/Hg.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.userOrderSum + '</td>\
								</tr>')
										break;
									case 3:
										$("#table_topUser").append('<tr><td><img class="award" src="../../images/cu.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.userOrderSum + '</td>\
								</tr>')
										break;
								}
								/*$("#table_topUser").append('</td>\
									<td><img src='+this.headPortraitUrl+'> '+this.nickname+'</td>\
									<td>'+this.userOrderSum+'</td>\
								</tr>')*/
								index++;

							})
							//alert(JSON.stringify(data))
						}
					},
					error: function() {
						alert("抱歉,服务器出错")
					}
				})
			}

			function addTopCourier() {
				$.ajax({
					url: "/randomdelivery/AdminController/topCourier/3",
					type: "GET",
					success: function(data) {
						if(data.code == 200) {
							$("#table_topCourier").text("")
							$("#table_topCourier").append("<tr>\
					<th>排名</th>\
					<th>活跃快递员</th>\
					<th>总接单数</th>\
				</tr>");
							var index = 1;
							$.each(data.couriers, function() {
								//alert(JSON.stringify(this))
								//$("#table_topUser").append('<tr><td><img class="award" ') ;
								switch(index) {
									case 1:
										$("#table_topCourier").append('<tr><td><img class="award" src="../../images/gold.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.sumOrder + '</td>\
								</tr>')
										break;
									case 2:
										$("#table_topCourier").append('<tr><td><img class="award" src="../../images/Hg.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.sumOrder + '</td>\
								</tr>')
										break;
									case 3:
										$("#table_topCourier").append('<tr><td><img class="award" src="../../images/cu.png"></td>\
									<td><img src=' + this.headPortraitUrl + '> ' + this.nickname + '</td>\
									<td>' + this.sumOrder + '</td>\
								</tr>')
										break;
								}
								/*$("#table_topUser").append('</td>\
									<td><img src='+this.headPortraitUrl+'> '+this.nickname+'</td>\
									<td>'+this.userOrderSum+'</td>\
								</tr>')*/
								index++;

							})
							//alert(JSON.stringify(data))
						}
					},
					error: function() {
						alert("抱歉,服务器出错")
					}
				})
			}

			function getDifferentOrder() {
				$.ajax({
					url: "/randomdelivery/AdminController/differentStateOrderNumber",
					success: function(data) {
						//alert(JSON.stringify(data))
						var index = 0;
						/*var data_state=[{
												"state": "未接单",
												"count": 0
											},{
												"state": "已接单",
												"count": 1
											},{
												"state": "正在采购",
												"count": 0
											},{
												"state": "采购完成",
												"count": 0
											},{
												"state": "正在寄件",
												"count": 0
											},{
												"state": "派送中",
												"count": 0
											},{
												"state": "已关闭",
												"count": 0
											},{
												"state": "待确认收货",
												"count": 1
											},{
												"state": "待评价",
												"count": 0
											}];*/

						var data_state = [];
						$.each(data.counts, function() {
							var count = this;
							switch(parseInt(index)) {
								case 0:
									data_state.push({
										"state": "未确认金额",
										"count": parseInt(count)
									})
									break;

								case 1:
									data_state.push({
										"state": "未支付",
										"count": parseInt(count)
									})
									break;

								case 2:
									data_state.push({
										"state": "已支付",
										"count": parseInt(count)
									})
									break;

								case 3:
									data_state.push({
										"state": "寻找快递员",
										"count": parseInt(count)
									})
									break;

								case 4:
									data_state.push({
										"state": "待取件",
										"count": parseInt(count)
									})
									break;

								case 5:
									data_state.push({
										"state": "派送中",
										"count": parseInt(count)
									})
									break;

								case 6:
									data_state.push({
										"state": "完成未评价",
										"count": parseInt(count)
									})
									break;

								case 8:
									data_state.push({
										"state": "退款中",
										"count": parseInt(count)
									})
									break;

								case 9:
									data_state.push({
										"state": "全部完成",
										"count": parseInt(count)
									})
									break;
							}
							index++;
						})
						state(data_state);

					},
					error: function() {
						alert("抱歉,服务器出错")
					}
				})
			}

			function state(data) {
				var statename = []
				var statenum = []
				$.each(data, function(index, val) {
					//alert(val.count)
					statename.push(val.state);
					statenum.push(val.count);
				});
				var myChart = echarts.init(document.getElementById('main'));
				// 指定图表的配置项和数据
				var option = {
					title: {
						text: '状态-订单数'
					},
					tooltip: {},
					legend: {
						data: ['订单数']
					},
					xAxis: {
						data: statename
					},
					yAxis: {},
					series: [{
						name: '订单数',
						type: 'bar',
						data: statenum
					}]
				};
				// 使用刚指定的配置项和数据显示图表。
				myChart.setOption(option);
			}
		</script>
	</body>

</html>